<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>✨ 文本反转工具 ✨</title>
    <style>
        :root {
            --primary: #4361ee;
            --primary-dark: #3a56d4;
            --secondary: #f72585;
            --light: #f8f9fa;
            --dark: #212529;
            --gray: #6c757d;
            --success: #4cc9f0;
        }
        
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        
        body {
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            line-height: 1.6;
            color: var(--dark);
        }
        
        .container {
            width: 100%;
            max-width: 600px;
            background: white;
            border-radius: 16px;
            padding: 40px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .container:hover {
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
        }
        
        h1 {
            color: var(--primary);
            text-align: center;
            margin-bottom: 30px;
            font-size: 2.2rem;
            font-weight: 700;
            position: relative;
            padding-bottom: 15px;
        }
        
        h1::after {
            content: "";
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 4px;
            background: var(--secondary);
            border-radius: 2px;
        }
        
        .form-group {
            margin-bottom: 25px;
        }
        
        label {
            display: block;
            margin-bottom: 12px;
            font-weight: 600;
            color: var(--dark);
            font-size: 1.1rem;
        }
        
        textarea {
            width: 100%;
            padding: 15px;
            border: 2px solid #e9ecef;
            border-radius: 8px;
            resize: vertical;
            min-height: 150px;
            font-family: inherit;
            font-size: 1rem;
            transition: all 0.3s;
            box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
        }
        
        textarea:focus {
            border-color: var(--primary);
            outline: none;
            box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
        }
        
        textarea::placeholder {
            color: var(--gray);
            opacity: 0.6;
        }
        
        button {
            background-color: var(--primary);
            color: white;
            border: none;
            padding: 16px 24px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 1.1rem;
            width: 100%;
            transition: all 0.3s;
            font-weight: 600;
            letter-spacing: 0.5px;
            text-transform: uppercase;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        button:hover {
            background-color: var(--primary-dark);
            transform: translateY(-2px);
            box-shadow: 0 7px 14px rgba(0, 0, 0, 0.15);
        }
        
        button:active {
            transform: translateY(0);
        }
        
        button:disabled {
            background-color: #adb5bd;
            cursor: not-allowed;
            transform: none;
        }
        
        .result-container {
            margin-top: 30px;
            opacity: 0;
            height: 0;
            overflow: hidden;
            transition: all 0.4s ease;
        }
        
        .result-container.show {
            opacity: 1;
            height: auto;
        }
        
        .result-title {
            color: var(--primary);
            margin-bottom: 15px;
            font-size: 1.3rem;
            display: flex;
            align-items: center;
        }
        
        .result-title svg {
            margin-right: 10px;
        }
        
        .result-box {
            background-color: #f8f9fa;
            border-left: 4px solid var(--success);
            padding: 20px;
            border-radius: 0 8px 8px 0;
            font-size: 1.1rem;
            line-height: 1.8;
            white-space: pre-wrap;
            word-break: break-word;
        }
        
        .error-container {
            margin-top: 20px;
            color: #dc3545;
            background-color: #f8d7da;
            padding: 15px;
            border-radius: 8px;
            border-left: 4px solid #dc3545;
            display: none;
        }
        
        .loading {
            text-align: center;
            margin: 25px 0;
            display: none;
        }
        
        .loading-spinner {
            border: 4px solid rgba(67, 97, 238, 0.1);
            border-top: 4px solid var(--primary);
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto 15px;
        }
        
        .loading-text {
            color: var(--primary);
            font-weight: 500;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .copy-btn {
            background-color: var(--success);
            margin-top: 20px;
            width: auto;
            padding: 12px 20px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
        }
        
        .copy-btn:hover {
            background-color: #3aa8d8;
        }
        
        .copy-btn svg {
            margin-right: 8px;
        }
        
        .footer {
            text-align: center;
            margin-top: 30px;
            color: var(--gray);
            font-size: 0.9rem;
        }
        
        @media (max-width: 768px) {
            .container {
                padding: 30px 20px;
            }
            
            h1 {
                font-size: 1.8rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>文本反转工具</h1>
        
        <div class="form-group">
            <label for="inputText">输入文本：</label>
            <textarea id="inputText" placeholder="请输入要反转的文本..."></textarea>
        </div>
        
        <button id="processBtn">反转文本</button>
        
        <div class="loading" id="loading">
            <div class="loading-spinner"></div>
            <p class="loading-text">正在处理您的请求，请稍候...</p>
        </div>
        
        <div class="error-container" id="errorContainer"></div>
        
        <div class="result-container" id="resultContainer">
            <h3 class="result-title">
                <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path>
                    <polyline points="22 4 12 14.01 9 11.01"></polyline>
                </svg>
                反转结果：
            </h3>
            <div class="result-box">
                <p id="outputText"></p>
            </div>
            <button class="copy-btn" id="copyBtn">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
                    <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
                </svg>
                复制结果
            </button>
        </div>
        
        <div class="footer">
            <p>© 2023 文本反转工具 | 轻量高效的文本处理</p>
        </div>
    </div>

    <script>
        // 保持原有逻辑完全不变
        document.addEventListener('DOMContentLoaded', () => {
            const processBtn = document.getElementById('processBtn');
            const inputText = document.getElementById('inputText');
            const outputText = document.getElementById('outputText');
            const resultContainer = document.getElementById('resultContainer');
            const errorContainer = document.getElementById('errorContainer');
            const loading = document.getElementById('loading');
            const copyBtn = document.getElementById('copyBtn');

            processBtn.addEventListener('click', async () => {
                const text = inputText.value.trim();
                if (!text) {
                    showError('请输入要反转的文本');
                    return;
                }

                resetUI();
                showLoading();

                try {
                    const response = await fetch(`http://localhost:8080/api/reverse?text=${encodeURIComponent(text)}`);
                    
                    if (!response.ok) {
                        throw new Error(`请求失败: ${response.status}`);
                    }
                    
                    const reversedText = await response.text();
                    outputText.textContent = reversedText;
                    showResult();
                    
                } catch (error) {
                    showError(`处理失败: ${error.message}`);
                    console.error('Error:', error);
                } finally {
                    hideLoading();
                }
            });

            copyBtn.addEventListener('click', () => {
                navigator.clipboard.writeText(outputText.textContent)
                    .then(() => {
                        const originalText = copyBtn.innerHTML;
                        copyBtn.innerHTML = `
                            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                <path d="M20 6L9 17l-5-5"/>
                            </svg>
                            复制成功!
                        `;
                        setTimeout(() => {
                            copyBtn.innerHTML = originalText;
                        }, 2000);
                    })
                    .catch(err => {
                        showError('复制失败，请手动选择文本复制');
                    });
            });

            function resetUI() {
                hideError();
                hideResult();
            }

            function showLoading() {
                loading.style.display = 'block';
                processBtn.disabled = true;
            }

            function hideLoading() {
                loading.style.display = 'none';
                processBtn.disabled = false;
            }

            function showResult() {
                resultContainer.classList.add('show');
            }

            function hideResult() {
                resultContainer.classList.remove('show');
            }

            function showError(message) {
                errorContainer.textContent = message;
                errorContainer.style.display = 'block';
            }

            function hideError() {
                errorContainer.style.display = 'none';
            }
        });
    </script>
</body>
</html>